﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CoreTest.Table.Join
{
    [TestClass]
    public class CombinatorialIteration
    {
        
        //public static void ExecuteAll( int length_of_x, int length_of_y ) {
        //    int[] indexes = new int[ length_of_x ];

        //    // we start at the last position, then work backwards
        //    for (int forward_x = 0; forward_x < length_of_x; forward_x++) {
        //        indexes[ forward_x ]++;

        //        for (int x = length_of_x - 1; x >= forward_x; x--)
        //        { 
        //            // this guy loops backward.
        //            for (int y = 0; y < length_of_y(x); y++) {
        //                indexes[ x ] = y;
        //            }
        //        }
        //    }
        //}

        [TestMethod]
        public void Test() {
            List<List<Object> > bucket_list = new List< List< object > >();
            for( int i=0 ; i < 5 ; i++ ) {
                List< Object > list = new List< Object >();
                bucket_list.Add( list );
                for( int j = 0 ; j < 5 ; j++ ) {
                    list.Add( i.ToString() +","+ j.ToString() );
                }
            }
            GetAll( bucket_list );
        }
        public static void GetAll(List<List<Object>> full_list )
        {
            int num_buckets = full_list.Count;
            int[] indexes = new int[num_buckets];

            // we start at the last position, then work backwards
            for (int forward_index = 0; forward_index < num_buckets; forward_index++)
            {
                indexes[forward_index]++;

                for (int back_index = num_buckets - 1; back_index >= forward_index; back_index--)
                {
                    // this guy loops backward.
                    for (int y = 0; y < full_list[back_index].Count; y++)
                    {
                        indexes[back_index] = y;

                        for (int i = 0; i < indexes.Length; i++ ) {
                            Console.Write( " " + indexes[i] + " ");
                        }
                        Console.WriteLine();
                    }
                }
            }
        }


        public static void GetAllCombinations( List< List< Object > > full_list ) {

            int bucket_count = full_list.Count;
            int total_length = 0;
            int[] row_counts = new int[bucket_count];
            for( int i=0 ; i < full_list.Count ; i++ ) {
                int sub_length = full_list[ i ].Count;
                total_length += sub_length;
                row_counts[ i ] = sub_length;
            }

            for( int outer_row_count=0 ; outer_row_count < row_counts[0] ; outer_row_count++ ) {
                for( int bucket_loop=1 ; bucket_loop < bucket_count ; bucket_loop++ ) {
                    List< Object > current_bucket = full_list[ bucket_loop ];
                    // we can keep slicing this
                }
            }
        }
    }
}
